package behaviourNavigatore;

import java.util.List;

import org.jgrapht.alg.DijkstraShortestPath;

import utility.Auto;
import utility.MyDefaultWeightedEdge;
import utility.Triple;

import navigatore.AgenteNavigatore;

import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;


public class GenerateRoute extends CyclicBehaviour{

	private static final long serialVersionUID = 1L;

	private AgenteNavigatore navigatore;
	
	@Override
	public void action() {


		navigatore = (AgenteNavigatore)myAgent;

		List<Auto> listCars1 = navigatore.getWaitingCarsWithoutWays();
		
		List<Auto> listCars2 = navigatore.getWaitingCarsWithWays();

		if(navigatore.cont2  && !listCars1.isEmpty()){
			
			navigatore.cont2=false;
			
			DijkstraShortestPath<Triple<Integer,Integer, String>, MyDefaultWeightedEdge> path;
			Triple<Integer,Integer, String> partenza, destinazione;


			while(!listCars1.isEmpty()) {

				Auto auto = listCars1.get(0);

				
				partenza = auto.getStart();
				destinazione = auto.getEnd();

				path = new DijkstraShortestPath<Triple<Integer,Integer, String>, MyDefaultWeightedEdge>(navigatore.getGraph(), partenza, destinazione);
				auto.setWay(path.getPathEdgeList());



				listCars2.add(auto);
				listCars1.remove(0);


			}

		}

		//listCars.clear();
	}

}